<?php


namespace app\demo\controller;

use app\BaseController;
use app\model\AdminUser;
use think\exception\HttpException;
use think\facade\Db;
use app\common\business\Demo1;
class Demo extends BaseController
{
 public function index(){
    // $result = Db::table("mall_admin_user")->where("id",0)->find();
     //通过容器的方式获取
     //$result =  app("db")->table("mall_admin_user")->where("id",0)->find();
     $result = Db::table("mall_admin_user")
         ->order("id","desc")
//         ->limit("1","2")
         ->select();
     dump( $result);
 }
 public function index2(){
/*
 * sql语句排查方式
 */
    // 打印sql的方式查询

    $result = Db::table("mall_admin_user")->where("id",0)->fetchSql()->find();
    dump($result);
    //输出sql的方式
     $res = Db::table("mall_admin_user")->where("id",0)->find();
     echo Db::getLastSql();
     exit();
 }
 public function model1(){
     $result = AdminUser::find(1);
     dump($result->toArray());
     return show(config("status.success"),"查询成功",$result,"200");
 }
 //五层架构调用实现
 public function index3(){
     $busDemo = new Demo1();
     $result = $busDemo->getAllUserList();
//     dump($result);
     return show(config("status.success"),"查询成功",$result);

 }
// 异常处理方法
public  function  index4(){
//     echo $abd;
    throw new HttpException(404,"找不到相关数据");
 }



}